package com.xbongbong.paas.controller.mobile;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.elasticsearch.pojo.dto.SearchDataInConditionDTO;
import com.xbongbong.paas.enums.PlatFormEnum;
import com.xbongbong.paas.field.LinkFormPoJo;
import com.xbongbong.paas.field.RelyPoJo;
import com.xbongbong.paas.pojo.FormTitlePoJo;
import com.xbongbong.paas.pojo.SummaryDataPoJo;
import com.xbongbong.paas.pojo.dto.ApprovePrintSubSummaryGetDTO;
import com.xbongbong.paas.pojo.dto.BusinessFormDataDTO;
import com.xbongbong.paas.pojo.dto.ButtonGetDTO;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataAddGetDTO;
import com.xbongbong.paas.pojo.dto.FormDataDeleteDTO;
import com.xbongbong.paas.pojo.dto.FormDataFastAddGetDTO;
import com.xbongbong.paas.pojo.dto.FormDataGetDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.FormDataOwnerDTO;
import com.xbongbong.paas.pojo.dto.FormDataRepeatDTO;
import com.xbongbong.paas.pojo.dto.FormDataSubSummaryGetDTO;
import com.xbongbong.paas.pojo.dto.FormDataUpdateBatchDTO;
import com.xbongbong.paas.pojo.dto.FormDataUpdateDTO;
import com.xbongbong.paas.pojo.dto.FormDataUpdateGetDTO;
import com.xbongbong.paas.pojo.dto.LinkDataListDTO;
import com.xbongbong.paas.pojo.dto.LinkFormDataDTO;
import com.xbongbong.paas.pojo.dto.LinkRelyDataDTO;
import com.xbongbong.paas.pojo.dto.LinkSearchListDTO;
import com.xbongbong.paas.pojo.dto.LinkWorkOrderPhoneDTO;
import com.xbongbong.paas.pojo.dto.WarehouseCheckDTO;
import com.xbongbong.paas.pojo.vo.ButtonGetVO;
import com.xbongbong.paas.pojo.vo.CheckRepeatVO;
import com.xbongbong.paas.pojo.vo.FormDataAddGetVO;
import com.xbongbong.paas.pojo.vo.FormDataAddVO;
import com.xbongbong.paas.pojo.vo.FormDataDeleteVO;
import com.xbongbong.paas.pojo.vo.FormDataGetVO;
import com.xbongbong.paas.pojo.vo.FormDataOwnerVO;
import com.xbongbong.paas.pojo.vo.FormDataSummaryVO;
import com.xbongbong.paas.pojo.vo.FormDataUpdateBatchVO;
import com.xbongbong.paas.pojo.vo.FormDataUpdateGetVO;
import com.xbongbong.paas.pojo.vo.FormDataUpdateVO;
import com.xbongbong.paas.pojo.vo.LinkDataListVO;
import com.xbongbong.paas.pojo.vo.LinkFormDataVO;
import com.xbongbong.paas.pojo.vo.LinkRelyDataVO;
import com.xbongbong.paas.pojo.vo.LinkRelyDataWorkOrderPhoneVO;
import com.xbongbong.paas.pojo.vo.LinkSearchListVO;
import com.xbongbong.paas.pojo.vo.PaasFormDataEsListVO;
import com.xbongbong.paas.pojo.vo.SearchDataInConditionVO;
import com.xbongbong.paas.redis.PaasRedisHelper;
import com.xbongbong.paas.service.LinkDataService;
import com.xbongbong.paas.service.PaasFormDataService;
import com.xbongbong.paas.service.ProFormDataService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.thread.TransmittableThreadLocalUtil;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.parent.interfaces.BusinessDetailTopInfoService;
import com.xbongbong.parent.interfaces.BusinessNewPageRenderService;
import com.xbongbong.pro.applist.pojo.AppListPojo;
import com.xbongbong.pro.applist.pojo.vo.ListAppVO;
import com.xbongbong.pro.businessdata.pojo.dto.ProductListDataDTO;
import com.xbongbong.pro.constant.XbbProConstant;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.errorcodes.ProductErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.formdata.pojo.dto.CheckDateDTO;
import com.xbongbong.pro.formdata.pojo.dto.DefaultOwnerAndCoUserGetDTO;
import com.xbongbong.pro.formdata.pojo.dto.FormDataDetailDTO;
import com.xbongbong.pro.formdata.pojo.dto.InheritRuleDTO;
import com.xbongbong.pro.formdata.pojo.vo.CheckDateVO;
import com.xbongbong.pro.formdata.pojo.vo.DefaultOwnerAndCoUserGetVO;
import com.xbongbong.pro.formdata.pojo.vo.InheritRuleVO;
import com.xbongbong.pro.formdata.pojo.vo.MobileFormCommonDetailVO;
import com.xbongbong.pro.fundtransfer.pojo.dto.CheckTransferDateDTO;
import com.xbongbong.pro.fundtransfer.pojo.vo.CheckTransferDateVO;
import com.xbongbong.pro.payment.pojo.dto.PaymentWriteOffDTO;
import com.xbongbong.pro.payment.pojo.vo.PaymentWriteOffVO;
import com.xbongbong.pro.warehouse.pojo.vo.WarehouseListVO;
import com.xbongbong.pro.weblist.pojo.dto.CustomerRepeatDTO;
import com.xbongbong.pro.weblist.pojo.dto.RepeatToolFieldGetDTO;
import com.xbongbong.pro.weblist.pojo.vo.CustomerRepeatVO;
import com.xbongbong.pro.weblist.pojo.vo.RecheckRepeatVO;
import com.xbongbong.pro.weblist.pojo.vo.RepeatFieldListVO;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.service.ListBatchService;
import com.xbongbong.saas.service.SaasListService;
import com.xbongbong.saas.service.toolbox.help.SaasListDataPermissionHelp;
import com.xbongbong.saas.toolbox.help.FastJsonHelper;
import com.xbongbong.sys.domain.entity.UserEntity;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author: wufeng
 * @date: 2018/9/12 9:47
 * @desrcption: 表单数据
 */
@RestController
@RequestMapping(XbbProConstant.API_ROOT_PREFIX + "/mobile/form/data")
public class MobilePaasFormDataController {

    @Resource
    private PaasFormDataService paasFormDataService;
    @Resource
    private PaasRedisHelper paasRedisHelper;
    @Resource
    private ProFormDataService proFormDataService;
    @Resource
    private SaasListService saasListService;
    @Resource
    private SaasListDataPermissionHelp saasListDataPermissionHelp;
    @Resource
    private ListBatchService listBatchService;
    @Resource
    private Map<Integer, BusinessDetailTopInfoService> businessDetailTopInfoMap;
    @Resource
    private LinkDataService linkDataService;
    @Resource
    private Map<Integer,BusinessNewPageRenderService> businessNewPageRenderMap;

    /**
     * 获取数据列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String list(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<PaasFormDataEsListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO formDataListVO = paasFormDataService.listByEs(formDataListDTO);
                response = new XbbResponse<>(formDataListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * 获取数据列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/customList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String customList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                UserEntity userEntity = new UserEntity();
                BeanUtil.copyProperties(formDataListDTO.getLoginUser(), userEntity);
                saasListDataPermissionHelp.dingtalkRangeScreen(formDataListDTO.getConditions(), userEntity, formDataListDTO.getBusinessType(), null, PlatFormEnum.DINGTALK.getValue());
                PaasFormDataEsListVO paasFormDataEsListVO = paasFormDataService.listByEs(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
                // 转格式
                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                List<AppListPojo> list = new ArrayList<>();
                if (totalCount != null && totalCount != 0) {
                    for (PaasFormDataEntityExt entity : esEntities) {
                        long id = entity.getDataId();
                        long appId = entity.getAppId();
                        long menuId = entity.getMenuId();
                        long formId = entity.getFormId();
                        JSONObject data = entity.getData();
                        List<SummaryDataPoJo> summaryList = FastJsonHelper.getJsonArrOrDefaultFromFormData(data, BasicConstant.SUMMARY_LIST, new JSONArray()).toJavaList(SummaryDataPoJo.class);
                        List<SummaryDataPoJo> lablesList = FastJsonHelper.getJsonArrOrDefaultFromFormData(data, BasicConstant.LABELS_LIST, new JSONArray()).toJavaList(SummaryDataPoJo.class);
                        List<FormTitlePoJo> titleList = FastJsonHelper.getJsonArrOrDefaultFromFormData(data, BasicConstant.TITLE_LIST, new JSONArray()).toJavaList(FormTitlePoJo.class);
                        list.add(new AppListPojo(id, titleList, summaryList, null, lablesList, (JSONObject) null, appId, menuId, formId));
                    }
                    listAppVO.setList(list);
                    listAppVO.setTotalCount(totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取数据列表
     * @param defaultOwnerAndCoUserGetDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/defaultOwnerAndCoUser/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getDefaultOwnerAndCoUser(@RequestBody @Valid DefaultOwnerAndCoUserGetDTO defaultOwnerAndCoUserGetDTO, BindingResult br) {
        XbbResponse<DefaultOwnerAndCoUserGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                DefaultOwnerAndCoUserGetVO defaultOwnerAndCoUserGetVO = paasFormDataService.getDefaultOwnerAndCoUser(defaultOwnerAndCoUserGetDTO);
                response = new XbbResponse<>(defaultOwnerAndCoUserGetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取继承关系，用于联合新建业务，判断下游的继承规则
     * @param inheritRuleDTO
     * @param
     * @param br
     * @return
     */
    @RequestMapping(value = "/getInheritRule", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getInheritRule(@RequestBody @Valid InheritRuleDTO inheritRuleDTO, BindingResult br) {
        XbbResponse<InheritRuleVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                InheritRuleVO inheritRuleVO = paasFormDataService.getInheritRule(inheritRuleDTO);
                response = new XbbResponse<>(inheritRuleVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 关联查询
     * @param linkDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/filter/link/search", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String filterLinkSearch(@RequestBody @Valid LinkSearchListDTO linkDataListDTO, BindingResult br) {
        XbbResponse<LinkSearchListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(linkDataListDTO.getSaasMark(), linkDataListDTO.getBusinessType(), linkDataListDTO.getMenuId(), linkDataListDTO.getDistributorMark());
                LinkSearchListVO linkDataVO = linkDataService.filterLinkSearch(linkDataListDTO);
                response = new XbbResponse<>(linkDataVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 数据列表根据字段返回可以选择的数据
     * @return
     */
    @RequestMapping(value = "/conditionList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String dataConditionList(@RequestBody @Valid SearchDataInConditionDTO searchDataInConditionDTO, BindingResult br){
        XbbResponse<SearchDataInConditionVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(searchDataInConditionDTO.getSaasMark(), searchDataInConditionDTO.getBusinessType(), searchDataInConditionDTO.getMenuId(), searchDataInConditionDTO.getDistributorMark());
                SearchDataInConditionVO searchDataInConditionVO = proFormDataService.dataConditionList(searchDataInConditionDTO);
                response = new XbbResponse<>(searchDataInConditionVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 关联数据
     * @param linkDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/filter/link/data", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String filterLinkData(@RequestBody @Valid LinkDataListDTO linkDataListDTO, BindingResult br) {
        XbbResponse<LinkDataListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(linkDataListDTO.getLinkInfo().getLinkSaasMark(), linkDataListDTO.getLinkInfo().getLinkBusinessType(), linkDataListDTO.getLinkInfo().getLinkMenuId(), linkDataListDTO.getDistributorMark());
                LinkDataListVO linkDataVO = linkDataService.filterLinkData(linkDataListDTO);
                response = new XbbResponse<>(linkDataVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 新建表单数据（需要返回表单字段描述）
     * @param formDataAddGetDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/add/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String addGet(@RequestBody @Valid FormDataAddGetDTO formDataAddGetDTO, BindingResult br) {
        XbbResponse<FormDataAddGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataAddGetDTO.getSaasMark(), formDataAddGetDTO.getBusinessType(), formDataAddGetDTO.getMenuId(), formDataAddGetDTO.getDistributorMark());
                FormDataAddGetVO formDataAddGetVO = paasFormDataService.addGet(formDataAddGetDTO);

                response = new XbbResponse<>(formDataAddGetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 工单联系方式
     */
    @RequestMapping(value = "linkWorkOrderPhone", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String linkWorkOrderPhone(@RequestBody @Valid LinkWorkOrderPhoneDTO linkWorkOrderPhoneDTO, BindingResult br) {
        XbbResponse<LinkRelyDataWorkOrderPhoneVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                LinkRelyDataWorkOrderPhoneVO linkRelyDataWorkOrderPhoneVO= paasFormDataService.linkWorkOrderPhone(linkWorkOrderPhoneDTO);
                response = new XbbResponse<>(linkRelyDataWorkOrderPhoneVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 快捷新建表单数据（需要返回表单字段描述，查重快速新建）
     * @param formDataFastAddGetDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/fastAdd/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String fastAddGet(@RequestBody @Valid FormDataFastAddGetDTO formDataFastAddGetDTO, BindingResult br) {
        XbbResponse<FormDataAddGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataFastAddGetDTO.getSaasMark(), formDataFastAddGetDTO.getBusinessType(), formDataFastAddGetDTO.getMenuId(), formDataFastAddGetDTO.getDistributorMark());
                FormDataAddGetVO formDataAddGetVO = paasFormDataService.fastAddGet(formDataFastAddGetDTO);
                response = new XbbResponse<>(formDataAddGetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 编辑表单数据（需要返回表单字段描述）
     * @param formDataUpdateGetDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/update/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String updateGet(@RequestBody @Valid FormDataUpdateGetDTO formDataUpdateGetDTO, BindingResult br) {
        XbbResponse<FormDataUpdateGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataUpdateGetDTO.getSaasMark(), formDataUpdateGetDTO.getBusinessType(), formDataUpdateGetDTO.getMenuId(), formDataUpdateGetDTO.getDistributorMark());
                FormDataUpdateGetVO formDataUpdateGetVO = paasFormDataService.updateGet(formDataUpdateGetDTO);

                response = new XbbResponse<>(formDataUpdateGetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取数据详情
     * @param formDataGetDTO
     * @param br
     * @return
     */

    @RequestMapping(value = "/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String detail(@RequestBody @Valid FormDataGetDTO formDataGetDTO, BindingResult br) {
        XbbResponse<FormDataGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataGetDTO.getSaasMark(), formDataGetDTO.getBusinessType(), formDataGetDTO.getMenuId(), formDataGetDTO.getDistributorMark());
                FormDataGetVO formDataGetVO = paasFormDataService.get(formDataGetDTO);
                response = new XbbResponse<>(formDataGetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description: 移动端detail
     * @param formDataGetDTO
     * @param br
     * @author 刘阳
     * @date 2019/6/28 5:14 PM
     * @since v1.0
     */
    @RequestMapping(value = "/basic/detail", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String basticDetail(@RequestBody @Valid FormDataGetDTO formDataGetDTO, BindingResult br) {
        XbbResponse<MobileFormCommonDetailVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataGetDTO.getSaasMark(), formDataGetDTO.getBusinessType(), formDataGetDTO.getMenuId(), formDataGetDTO.getDistributorMark());
                MobileFormCommonDetailVO mobileFormCommonDetailVO = paasFormDataService.getMoblieDetail(formDataGetDTO);
                response = new XbbResponse<>(mobileFormCommonDetailVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 移动端detail页快速编辑接口，主要是标签的快速编辑，复用了web端的快速编辑
     * @param formDataUpdateBatchDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/batch/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String update(@RequestBody @Valid FormDataUpdateBatchDTO formDataUpdateBatchDTO, BindingResult br) {
        XbbResponse<FormDataUpdateBatchVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataUpdateBatchDTO.getSaasMark(), formDataUpdateBatchDTO.getBusinessType(), formDataUpdateBatchDTO.getMenuId(), formDataUpdateBatchDTO.getDistributorMark());
                FormDataUpdateBatchVO formDataUpdateBatchVO = listBatchService.updateBatch(formDataUpdateBatchDTO);
                response = new XbbResponse<>(formDataUpdateBatchVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 删除单条数据
     * @param formDataDeleteDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String delete(@RequestBody @Valid FormDataDeleteDTO formDataDeleteDTO, BindingResult br) {
        XbbResponse<FormDataDeleteVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormDataDeleteVO formDataDeleteVO = paasFormDataService.delete(formDataDeleteDTO);
                response = new XbbResponse<>(formDataDeleteVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 保存单条数据
     * @param formDataSaveDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String save(@RequestBody @Valid FormDataAddDTO formDataSaveDTO, BindingResult br) {
        XbbResponse<FormDataAddVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(formDataSaveDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(formDataSaveDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                TransmittableThreadLocalUtil.setValue(formDataSaveDTO.getSaasMark(), formDataSaveDTO.getBusinessType(), formDataSaveDTO.getMenuId(), formDataSaveDTO.getDistributorMark());
                FormDataAddVO formDataSaveVO = paasFormDataService.add(formDataSaveDTO);
                response = new XbbResponse<>(formDataSaveVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 保存单条数据
     * @param formDataUpdateDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String update(@RequestBody @Valid FormDataUpdateDTO formDataUpdateDTO, BindingResult br) {
        XbbResponse<FormDataUpdateVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataUpdateDTO.getSaasMark(), formDataUpdateDTO.getBusinessType(), formDataUpdateDTO.getMenuId(), formDataUpdateDTO.getDistributorMark());
                FormDataUpdateVO formDataUpdateVO = paasFormDataService.update(formDataUpdateDTO);
                response = new XbbResponse<>(formDataUpdateVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 更改负责人
     * @param formDataOwnerDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/update/owner", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String updateOwner(@RequestBody @Valid FormDataOwnerDTO formDataOwnerDTO, BindingResult br) {
        XbbResponse<FormDataOwnerVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormDataOwnerVO formDataOwnerVO = paasFormDataService.updateOwner(formDataOwnerDTO);
                response = new XbbResponse<>(formDataOwnerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 下拉框-选项-联动其他表单
     */
    @RequestMapping(value = "link/form/data", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String linkFormData(@RequestBody @Valid LinkFormDataDTO linkFormDataDTO, BindingResult br) {
        XbbResponse<LinkFormDataVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                LinkFormPoJo linkFormPoJo = linkFormDataDTO.getLinkForm();
                TransmittableThreadLocalUtil.setValue(linkFormPoJo.getSourceSaasMark(), linkFormPoJo.getSourceBusinessType(), linkFormPoJo.getSourceMenuId(), linkFormDataDTO.getDistributorMark());
                LinkFormDataVO linkFormDataVO = paasFormDataService.linkFormData(linkFormDataDTO);
                response = new XbbResponse<>(linkFormDataVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 下拉框-选项-数据联动
     */
    @RequestMapping(value = "link/rely/data", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String linkRelyData(@RequestBody @Valid LinkRelyDataDTO linkRelyDataDTO, BindingResult br) {
        XbbResponse<LinkRelyDataVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                RelyPoJo relyPoJo = linkRelyDataDTO.getRely();
                TransmittableThreadLocalUtil.setValue(relyPoJo.getSourceSaasMark(), relyPoJo.getSourceBusinessType(), relyPoJo.getSourceMenuId(), linkRelyDataDTO.getDistributorMark());
                LinkRelyDataVO linkRelyDataVO= paasFormDataService.linkRelyData(linkRelyDataDTO);
                response = new XbbResponse<>(linkRelyDataVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 查询重复信息
     * @param formDataRepeatDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/repeat", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String repeat(@RequestBody @Valid FormDataRepeatDTO formDataRepeatDTO, BindingResult br) {
        XbbResponse<CheckRepeatVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                formDataRepeatDTO.setIsEdit(false);
                CheckRepeatVO checkRepeatVO = paasFormDataService.repeat(formDataRepeatDTO);
                response = new XbbResponse<>(checkRepeatVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 保存多条数据
     * @param formDataSaveDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/addBatch", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String addBatch(@RequestBody @Valid FormDataAddDTO formDataSaveDTO, BindingResult br) {
        XbbResponse<FormDataAddVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormDataAddVO formDataSaveVO = paasFormDataService.addBatch(formDataSaveDTO);
                response = new XbbResponse<>(formDataSaveVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * Description: 获取数据详情tab页面(工单)
     * @param mobileFormDataDetailDTO
     * @param br
     * @return java.lang.String
     * @author 刘阳
     * @date 2019/5/6 2:43 PM
     * @since v1.0
     */
    @RequestMapping(value = "/detail", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String detail(@RequestBody @Valid FormDataDetailDTO formDataDetailDTO, BindingResult br) {
        XbbResponse<MobileFormCommonDetailVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(SaasMarkEnum.SAAS.getCode(), XbbRefTypeEnum.WORK_ORDER.getCode(), null, formDataDetailDTO.getDistributorMark());
                BusinessDetailTopInfoService businessDetailTopInfoService = businessDetailTopInfoMap.get(XbbRefTypeEnum.WORK_ORDER.getCode());
                MobileFormCommonDetailVO mobileFormCommonDetailVO = businessDetailTopInfoService.getMobileDetail(formDataDetailDTO);

//                TransmittableThreadLocalUtil.setValue(SaasMarkEnum.SAAS.getCode(), XbbRefTypeEnum.WORK_ORDER.getCode(), null, mobileFormDataDetailDTO.getDistributorMark());
//                MobileFormDataDetailVO mobileFormDataDetailVO = paasFormDataService.getWorkOrderMoblieDetail(mobileFormDataDetailDTO);
                response = new XbbResponse<>(mobileFormCommonDetailVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description: 产品扫描
     * @param productListDataDTO
     * @param br
     * @author 魏荣杰
     * @date 2019/5/29 10:29
     * @since v1.0
     */
    @RequestMapping(value = "/product/scanBarcode", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String scanBarcode(@RequestBody @Valid ProductListDataDTO productListDataDTO, BindingResult br) {
        XbbResponse<PaasFormDataEsListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(productListDataDTO.getSaasMark(), productListDataDTO.getBusinessType(), null, productListDataDTO.getDistributorMark());
                PaasFormDataEsListVO paasFormDataEsListVO = paasFormDataService.getProductList(productListDataDTO);
                if (Objects.nonNull(paasFormDataEsListVO) && paasFormDataEsListVO.getPaasFormDataESList().size() == 0) {
                    throw new XbbException(ProductErrorCodeEnum.API_ERROR_205022);
                }
                response = new XbbResponse<>(paasFormDataEsListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 按钮类型字段编辑表单数据（需要返回表单字段描述）
     * @param buttonGetDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/button/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String buttonGet(@RequestBody @Valid ButtonGetDTO buttonGetDTO, BindingResult br) {
        XbbResponse<ButtonGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ButtonGetVO buttonGetVO = paasFormDataService.buttonGet(buttonGetDTO);
                response = new XbbResponse<>(buttonGetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 客户列表查重渲染
     * @param customerRepeatDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/customerRepeat", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String customerRepeat(@RequestBody @Valid CustomerRepeatDTO customerRepeatDTO, BindingResult br) {
        XbbResponse<CustomerRepeatVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CustomerRepeatVO repeatVO = paasFormDataService.customerRepeat(customerRepeatDTO);
                response = new XbbResponse<>(repeatVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 客户列表查重渲染
     * @param customerRepeatDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/getRepeatMenu", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getRepeatMenu(@RequestBody @Valid CustomerRepeatDTO customerRepeatDTO, BindingResult br) {
        XbbResponse<RecheckRepeatVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                RecheckRepeatVO repeatVO = paasFormDataService.getRepeatMenu(customerRepeatDTO);
                response = new XbbResponse<>(repeatVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     *  常用查重搜索
     * @param repeatToolFieldGetDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/repeatTool/repeatField", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getRepeatField(@RequestBody @Valid RepeatToolFieldGetDTO repeatToolFieldGetDTO, BindingResult br) {
        XbbResponse<RepeatFieldListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                RepeatFieldListVO repeatFieldListVO = paasFormDataService.getRepeatField(repeatToolFieldGetDTO);
                response = new XbbResponse<>(repeatFieldListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 子表单内的数据汇总
     * @param
     * @param br
     * @return
     */
    @RequestMapping(value = "/subSummary", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String subSummary(@RequestBody @Valid FormDataSubSummaryGetDTO formDataSubSummaryGetDTO, BindingResult br) {
        XbbResponse<FormDataSummaryVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormDataSummaryVO formDataSummaryVO = paasFormDataService.getFormDataSubSummary(formDataSubSummaryGetDTO);
                response = new XbbResponse<>(formDataSummaryVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 审批打印子表单数字字段汇总
     *
     * @param
     * @param br
     * @throws
     * @return
     * @author: 曹远远
     * @date: 2020-04-28
     * @since:
     * @version:
     */
    @RequestMapping(value = "/subPrintSummary", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String subPrintSummary(@RequestBody @Valid ApprovePrintSubSummaryGetDTO approvePrintSubSummaryGetDTO, BindingResult br) {
        XbbResponse<FormDataSummaryVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try{
                FormDataSummaryVO formDataSummaryVO = paasFormDataService.getFormDataPrintSubSummary(approvePrintSubSummaryGetDTO);
                response = new XbbResponse<>(formDataSummaryVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 下拉框-搜索工商查询匹配
     * @param businessFormDataDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/business/data", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String businessComboData(@RequestBody @Valid BusinessFormDataDTO businessFormDataDTO, BindingResult br) {
        XbbResponse<LinkFormDataVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(businessFormDataDTO.getSaasMark(), businessFormDataDTO.getBusinessType(), businessFormDataDTO.getMenuId(), businessFormDataDTO.getDistributorMark());
                LinkFormDataVO linkFormDataVO = proFormDataService.businessComboData(businessFormDataDTO);
                response = new XbbResponse<>(linkFormDataVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 校检仓库是否可用
     * @param warehouseCheckDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/checkWarehouse", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String checkWarehouse(@RequestBody @Valid WarehouseCheckDTO warehouseCheckDTO, BindingResult br) {
        XbbResponse<WarehouseListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                WarehouseListVO warehouseListVO = paasFormDataService.checkWarehouse(warehouseCheckDTO);
                response = new XbbResponse<>(warehouseListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * 应收款核销
     * @param paymentWriteOffDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/payment/writeOff", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String paymentWriteOff(@RequestBody @Valid PaymentWriteOffDTO paymentWriteOffDTO, BindingResult br) {
        XbbResponse<PaymentWriteOffVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(paymentWriteOffDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(paymentWriteOffDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                PaymentWriteOffVO paymentWriteOff = paasFormDataService.paymentWriteOff(paymentWriteOffDTO);
                response = new XbbResponse<>(paymentWriteOff);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 移动端资金调拨单 - 校验调拨日期
     * @param checkTransferDateDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/fundTransfer/checkTransferDate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String checkTransferDate(@RequestBody @Valid CheckTransferDateDTO checkTransferDateDTO, BindingResult br) {
        XbbResponse<CheckTransferDateVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CheckTransferDateVO checkDateVO = paasFormDataService.checkTransferDate(checkTransferDateDTO);
                response = new XbbResponse<>(checkDateVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取当前日期之后是否还有单据
     * @param checkDateDTO
     * @param br
     * @returnadd
     */

    @RequestMapping(value = "/checkDate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String checkDate(@RequestBody @Valid CheckDateDTO checkDateDTO, BindingResult br) {
        XbbResponse<CheckDateVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CheckDateVO checkDateVO = paasFormDataService.checkDate(checkDateDTO);
                response = new XbbResponse<>(checkDateVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 删除时间获取当前日期之后是否还有单据
     * @param checkDateDTO
     * @param br
     * @returnadd
     */
    @RequestMapping(value = "/delete/checkDate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String deleteCheckDate(@RequestBody @Valid CheckDateDTO checkDateDTO, BindingResult br) {
        XbbResponse<CheckDateVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {

                CheckDateVO checkDateVO = paasFormDataService.deleteCheckDate(checkDateDTO);
                response = new XbbResponse<>(checkDateVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
}
